<?php
	session_start();

	foreach($_REQUEST as $key => $value)  {
		$$key = $value;
		#echo $key.'='.$value."<br>";
	}
	
	$time = time(); // Gets the current server time 		
	include("class.function.php");
	$inancm = new inancm();
	
	error_reporting(E_ALL ^ E_NOTICE);
	
	$find = 0;
	
	$sql = "SELECT COUNT(admin_id) AS finddata FROM inancm_admin ";
	$sql .= "WHERE admin_username = '".trim($username)."' AND admin_password = '".trim($password)."'";
	$get_finddata = $inancm->select_db($sql);
	//$inancm->pre($get_finddata);	
	$finddata = $get_finddata[0]['finddata'];
	
	if ($finddata > 0){	
	
		$sql_admin = "SELECT * FROM inancm_admin ";
		$sql_admin .= "WHERE admin_username = '".trim($username)."' AND admin_password = '".trim($password)."' ";
		$get_dataadmin = $inancm->select_db($sql_admin);
		//$inancm->pre($get_dataadmin);
		$_SESSION['inancm_username'] = $username;
		$_SESSION['inancm_name'] = $get_dataadmin[0]['admin_name'];
		$_SESSION['inancm_id'] = $get_dataadmin[0]['admin_id'];		
		$_SESSION['pass_actived'] = 'actived';
		
		echo "<div style='font-weight:bold;' class='success'>เข้าสู่ระบบโดย : <strong>".$username."</strong></div>";
		echo "<script>window.location='index.php';</script>";
		/*echo "<meta http-equiv=\"refresh\" content=\"2;URL=index.php\">";*/
		
	} else {
		echo "<div style='font-weight:bold;' class='error'>ไม่สามารถเข้าสู่ระบบได้</div>";	
	}
	//ob_end_flush();
?>